<template>
  <div>
    <router-link
      class="header-abs"
      to="/"
      tag='div'
      v-show="showAbs">
      <div class="iconfont iconfanhui header-abs-back"></div>
    </router-link>
    <div
      class="header-fixed"
      v-show="!showAbs"
      :style="opacityStyle">
      <router-link to='/'>
        <div class="iconfont iconfanhui header-fixed-back"></div>
      </router-link>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  mounted () {
    window.addEventListener('scroll', this.handleScroll)
  },
  unmounted () {
    window.removeEventListener('scroll', this.handleScroll)
  },
  methods: {
    handleScroll () {
      const scrollTop = document.documentElement.scrollTop
      if (scrollTop > 60) {
        let opacity = scrollTop / 140
        opacity = opacity > 1 ? 1 : opacity
        this.showAbs = false
        this.opacityStyle = {
          opacity: opacity
        }
      } else {
        this.showAbs = true
      }
    }
  }
}

</script>
<style lang="stylus" scoped>
 @import "~styles/varibles.styl"
  .header-abs
    position absolute
    left .2rem
    top .2rem
    width .8rem
    line-height .8rem
    height .8rem
    border-radius .4rem
    background-color rgba(0, 0, 0, .75)
    text-align center
    .header-abs-back
      color #fff
      font-size .4rem
  .header-fixed
    z-index 2
    width: 100%
    height $headerHeight
    line-height $headerHeight
    background-color $bgColor
    text-align center
    color #fff
    font-size .32rem
    position fixed
    top 0
    left 0
    right 0
    .header-fixed-back
      width: .64rem
      position absolute
      font-size .4rem
      text-align center
      top 0
      left 0
      color #fff
</style>
